<%@ page language="java" import="java.util.*" %>
<%@ page import="org.gatorojo.model.Product" %>

<%
	String contextPath = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + contextPath +"/";
%>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>List Products</title>
		<link rel="stylesheet" href="<%=contextPath%>/view/css/gatorojo.css" type="text/css" media="screen"/>		
		<script type="text/javascript" src="<%=contextPath%>/view/js/jquery-1.4.2.min.js" charset="utf-8"></script>
		<script type="text/javascript" charset="utf-8">
			var $jq = jQuery.noConflict();
		</script>
	</head>
	<body>
		<div id="banner">
			<center>
				<img src="<%=contextPath%>/view/images/gatoRojo.jpg" width="120" height="120"/><h1>Product Store</h1>			
			</center>
		</div>
		<div id="message">
			<% 
				String message = (String)session.getAttribute("message");
				if(message != null) {
			%>
					<img src="<%=contextPath%>/view/images/info.png" width="50" height="50"/>&nbsp;
					<%=message%>									
					<br />
			<%
				} else {
			%>
					<br />
			<%
				}
			%>
		</div>
		
			<%
			@SuppressWarnings("unchecked")
			//Collection<Product> products = (Collection<Product>)session.getServletContext().getAttribute("products");
			Collection<Product> products = (Collection<Product>)session.getAttribute("products");
			
				if(products == null)
				{
					products = (Collection<Product>)session.getServletContext().getAttribute("products");
				}
					
					%>
					<center>
					<table border="1">  		
				  		<tr>
							<th>Product Code</th>
							<th>Product Name</th>
							<th>Product Stock</th>
							<th>Update</th>
							<th>Delete</th>
						</tr>
					<%
					for (Product product:products) {
					%>
			 		<tr>
				 			<td>
				 				<%out.print(product.getCode());%>
				 			</td>
				 							 			
				 			<td>
				 				<%out.print(product.getName());%>
				 			</td>
				 			
				 			<td>
				 				<%out.print(product.getStock());%>
				 			</td>
				 			
				 			<td>
				 				<a href="<%=contextPath%>/GatoRojo?action=SHOW_UPDATE&productCode=<%out.print(product.getCode());%>"><img src="<%=contextPath%>/view/images/update.png" width="24px" height="24px" /></a>				 				
				 			</td>				 						 		
				 			
				 			<td>
				 				<a href="<%=contextPath%>/GatoRojo?action=SHOW_DELETE&productCode=<%out.print(product.getCode());%>"><img src="<%=contextPath%>/view/images/delete.png" width="24px" height="24px" /></a>
				 			</td>
			 		</tr>
			 		<%
			 		}
					%>
					</table>
					</center>
					<br />
					<a href="<%=contextPath%>/GatoRojo?action=SHOW_ADD">Add Product <img src="<%=contextPath%>/view/images/add.png" width="24px" height="24px" /></a>								
					<!-- out.println("<td>" + element.getAuthor() + "</td>"); -->			 		
					<%
				
			%>
				</body>
</html>
		
